package rg.edu.ap.web.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import rg.edu.ap.po.Bath;
import rg.edu.ap.po.Seat;
import rg.edu.ap.po.User;
import rg.edu.ap.service.BathService;
import rg.edu.ap.service.SeatService;
import rg.edu.ap.service.UserService;


@Controller
public class UserController {
      
	@Autowired
	private UserService userService;
	@Autowired
	private SeatService seatservice;
	@Autowired
	private BathService bathservice;
	
	@RequestMapping("/aaa.action")
	public String logincheck(int userid) {
		User u = userService.ff(userid);
		System.out.println(u.getUsername());
	   return "Vicinity";
	}
	
	@RequestMapping("/map")
	public String goMap() {
	   return "map";
	}
	
	@RequestMapping("/main.action")
	public String goMain() {
	   return "main";
	}
	
	@RequestMapping("/login.action")
	public String goLogin() {
	   return "login";
	}
	@RequestMapping("/register.action")
	public String goRegister() {
	   return "register";
	}
	
	@RequestMapping("/vicinity.action")
	public String goVicinity() {
	   return "Vicinity";
	}
	
	@RequestMapping("/mypage.action")
	public String goMypage() {
	   return "mypage";
	}
	
	@RequestMapping("/adduser.action")
	public String addUser(User user) {
		userService.addUser(user);
	   return "main";
	}
	
	@RequestMapping("/usermap.action")
	public String updateUsermap(User user) {
		userService.updateUsermap(user);
	   return "Vicinity";
	}
	
	@RequestMapping("/maplt.action")
	public String maplt(double lng,double lat) {
		System.out.println(lng+"*****"+lat);
	   return "main";
	}
	
	@RequestMapping("/order.action")
	public String order(int userid,Model model) {
		List<Seat> list = seatservice.findOrderSeat(userid);
		model.addAttribute("ORDER_SEAT_LIST", list);
		Bath bath=bathservice.getBathid(list.get(0).getMerid());
		model.addAttribute("ORDER_BATH_LIST", bath);
	   return "order";
	}
	
	@RequestMapping("/finduser.action")
	public String findUser(int userid,Model model) {
		User user = userService.findUser(userid);
		model.addAttribute("userone",user);
	   return "updateuser";
	}
	
	@RequestMapping("/updateuser.action")
	public String updateUser(User user) {
		userService.updateUser(user);
	   return "mypage";
	}
	
	@RequestMapping("/loginn.action")
	public String loginUser(User user,HttpSession session) {
		User u = userService.loginUser(user);
		System.out.println(u.getUsername());
		if(u!=null) {
			session.setAttribute("USER_SESSION_USER", u);
		}
	   return "main";
	}
}
